const User = require("../models/User")
const JwtStrategy = require('passport-jwt').Strategy
const ExtractJwt = require('passport-jwt').ExtractJwt
const tokenSecret = require('./keys').tokenSecret
const opts = {}
opts.jwtFromRequest = ExtractJwt.fromAuthHeaderAsBearerToken();
opts.secretOrKey = tokenSecret;


module.exports = passport => {
  passport.use(new JwtStrategy(opts, async function (jwt_payload, done) {
    let user = await User.findById({_id: jwt_payload.id})
    console.log(user);

    if (user) {
      return done(null, user);
    } else {
      return done(null, false);
    }

  }));
}


